﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

namespace Cm.Web.Common
{
    /// <summary>
    /// 程序初始化器
    /// </summary>
    public class AppInitializer
    {
        protected HttpApplication _app = null;
        /// <summary>
        /// 是否启用包含角色信息的Form验证
        /// </summary>
        public bool EnableFormsAuthenticationWithRole { get; set; }
        public AppInitializer(HttpApplication app)
        {
            _app = app;
        }

        public virtual void Init()
        {
            if (EnableFormsAuthenticationWithRole)//开启角色的Form验证
            {
                _app.PostAuthenticateRequest += new EventHandler(_app_PostAuthenticateRequest);     
            }
           
        }

        void _app_PostAuthenticateRequest(object sender, EventArgs e)
        {
            FormsAuthenticationWithRole.InitializeFormsAuthenticationInfo();
        }
    }
}
